package com.lhb.boyixue.user.controller;

import com.lhb.boyixue.base.UnifyResponseObject;
import com.lhb.boyixue.user.utils.XunfeiSpeechTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static com.mysql.cj.conf.PropertyKey.logger;

/**
 * @author 86131
 * @version 1.0
 * @description Ai相关接口
 * @date 2025/6/17 下午11:07
 */
@RestController
@RequestMapping("/AI")
@Slf4j
public class AiController {

    @PostMapping("/voice")
    public UnifyResponseObject<String> voice(@RequestParam("audioFile") MultipartFile audioFile) {
        try {
            // 检查文件
            if (audioFile.isEmpty()) {
                log.error("上传的音频文件为空");
                return UnifyResponseObject.fail("音频文件为空");
            }
            byte[] audioData = audioFile.getBytes();
            return UnifyResponseObject.success(XunfeiSpeechTool.recognizeAudio(audioData),"成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
